package org.belkodevelop.role.dao;

import java.util.List;
import org.belkodevelop.role.domain.Role;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class RoleDAOImpl implements RoleDAO {
    
    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public List<Role> listRoles() {
        return (List<Role>)sessionFactory.getCurrentSession().createQuery("from roles").list();
    }
        
    @Override
    public Role getRole(String name) {
        return (Role)sessionFactory.getCurrentSession().
                createCriteria(Role.class).add(Restrictions.eq("name", name)).uniqueResult();
    }
}
